<?php
class Zendvn_View_Helper_CmsSelect extends Zend_View_Helper_Abstract{
	
	
	public function cmsSelect($name,$value = null,$attribs = null,$options = null ){
		
		$strAttribs = '';
		if(count($attribs)>0){
			foreach ($attribs as $key => $val){
				$strAttribs .= ' ' . $key . '="' . $val . '" ';
			}
		}		
		if (isset($attribs['multiple']) && $attribs['multiple'] == 'multiple') {
            $name .= '[]';
        }		
		$xhtml = '<select name="' . $name . '" id="' . $name . '" ' . $strAttribs . '>';
		if(!empty($options)){
			foreach ($options as $key => $val){
				$selected = '';
				if(is_array($value)){
					foreach ($value as $k => $v){
						if($val['id'] == $v){
							$selected = 'selected="selected"';
						}
					}
				}else{
					if($val['id'] == $value){
						$selected = 'selected="selected"';
					}
				}
				
				$name = $val['name'];
				if($val['level'] == 1){
					$name = '+ ' . $val['name'];
				}else{
					$str = '- - ';
					$name = ' ' . @str_repeat($str, $val['level'] - 1) . $val['name'];
				}
				$xhtml .= '<option value="' . $val['id'] . '" ' . $selected . ' >' . $name . '</option>';
			}
		}
		$xhtml .= '</select>';
		
		return $xhtml;
	}
}